 <template>
	<view class="content">
		<u-form :model="form" ref="uForm">
			<u-form-item label="姓名"><u-input v-model="form.doctorName"/></u-form-item>
			<u-form-item label="科"><u-input v-model="deptsort" type="select" @click="choosedeptsort"/></u-form-item>
			<u-select v-model="showradioList2" :list="radioList2" @confirm="confirmradioList2"></u-select>
			<u-form-item label="室"><u-input v-model="deptname" type="select" @click="choosedeptId"/></u-form-item>
			<u-select v-model="showradioList3" :list="radioList3" @confirm="confirmradioList3"></u-select>
			<u-form-item label="机构"><u-input v-model="form.orgName"/></u-form-item>
			
			<u-form-item label="职称"><u-input v-model="form.levelName" type="select" @click="chooselevelName"/></u-form-item>
			<u-select v-model="showradioList" :list="radioList" @confirm="confirmradioList"></u-select>
		</u-form>
		<u-button class="buttonbox" @click="submit">提交</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showradioList:false,
				showradioList2:false,
				showradioList3:false,
				deptsort:'',
				deptname:'请选择科室',
				form: {
					nickName:'',
					doctorName:'',
					deptId:1,
					orgName:'',
					levelName:''
				},
				radioList: [
					{
						label: '主任医师',
						value:1
					},
					{
						label: '副主任医师',
						value:2
					},
					{
						label: '主治医师',
						value:3
					},
					{
						label: '医师',
						value:4
					},
					{
						label: '医士',
						value:5
					}
				],
				radioList2:[],
				radioList3:[]
			};
		},
		methods:{
			choosedeptsort(){
				this.showradioList2=true
			},
			choosedeptId(){
				this.showradioList3=true
			},
			chooselevelName(){
				console.log("test")
				this.showradioList=true
			},
			confirmradioList(e){
				this.form.levelName=e[0].label;
			},
			confirmradioList2(e){
				this.deptsort=e[0].label;
				var deptSpecieslist=[];
				uni.request({
				    url: getApp().globalData.hostip+'Demo/department/findDep?species='+this.deptsort, 
				    data:{
					},
					fail:(fa) =>{
						console.log(fa)
					},
				    success: (res) => {
						res.data.forEach(function(temp){
							deptSpecieslist.push({
								label:temp.deptName,
								value:temp.deptId
							})
						})
				    }
				});
				this.radioList3=deptSpecieslist;
			},
			confirmradioList3(e){
				this.form.deptId=e[0].value
				this.deptname=e[0].label
			},
			submit(){
				console.log(getApp().globalData.userinfo.nickName)
				uni.request({
				    url: getApp().globalData.hostip+'Demo/doctor/add', 
					method: 'POST',
				    data: {
						doctorId:getApp().globalData.userinfo.nickName,
						deptId:this.form.deptId,
						doctorName:this.form.doctorName,
						orgName:this.form.orgName,
						levelName:this.form.levelName
					},
					header: {
						'Content-Type': 'application/json',
					},
					fail:(fa) =>{
						console.log(fa)
					},
				    success: (res) => {
						console.log(res.data)
				    }
				});
				var form2=this.form;
				getApp().globalData.doctorinfo=this.form
				console.log(form2)
				// setTimeout(function () {
				// 	uni.request({
				// 	    url: getApp().globalData.hostip+'Demo/doctor/upload', 
				// 		method: 'POST',
				// 	    data: {
				// 			doctorId:getApp().globalData.userinfo.nickName,
				// 			deptId:getApp().globalData.doctorinfo.deptId,
				// 			doctorName:getApp().globalData.doctorinfo.doctorName,
				// 			orgName:getApp().globalData.doctorinfo.orgName,
				// 			heading:"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b32b5cb2-8bc8-483a-8465-e7b67cc35291/a07bb878-bc83-4a2c-b784-61e97267ee83.png",
				// 		},
				// 		header: {
				// 			'Content-Type': 'application/json',
				// 		},
				// 		fail:(fa) =>{
				// 			console.log(fa)
				// 		},
				// 	    success: (res) => {
				// 			console.log(res.data)
				// 	    }
				// 	});
				// },2000)
				uni.switchTab({
					url:"doctor_mainpage"
				})
			}
		},
		onLoad:function (option){
			this.form.nickName=getApp().globalData.userinfo.nickName;
			var deptSpecieslist=[];
			uni.request({
			    url: getApp().globalData.hostip+'Demo/department/findSpec', 
			    data:{
				},
				fail:(fa) =>{
					console.log(fa)
				},
			    success: (res) => {
					res.data.forEach(function(temp){
						deptSpecieslist.push({
							label:temp.deptSpecies
						})
					})
			    }
			});
			this.radioList2=deptSpecieslist;
		}
	};
</script>

<style scopped>
	.content{
		margin-left: 20rpx;
		margin-right: 20rpx;
	}
	.buttonbox{
		margin-top: 100rpx;
	}
</style>
